package Model;
/*
 * Author - SAMBA.R
 */

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Date;

import org.junit.Test;

import FileParser.FileParser;
import Model.Author;
import Model.Conference;
import Model.Manuscript;
import Model.Roles;

public class FileParserJunitTest {

	FileParser fp = new FileParser();
	Conference conf = new Conference("100", "06/03/2012", "UW Tacoma", "11/03/2013");
	Author author = new Author(fp, "Clint Eastwood", conf);
	Reviewer reviewer = new Reviewer(fp, "Rod Stiffington", conf);
	
	// insert manuscript test
	@Test
	public void insertManuscript() {
		
		ArrayList<Manuscript> mList = new ArrayList<Manuscript>();
		Manuscript new_manuscript = new Manuscript(author.getName(), "New Manuscript Heading", "/Papers/Hello.docx", conf);
		mList.add(new_manuscript);
		
		fp.insertManuscript(conf.getName(), mList);
		
		ArrayList<Manuscript> manuscriptsList = fp.getManuscripts(Roles.AUTHOR.toString(), author.getName(), conf.getName());
		// assuming that conference 100 has two manuscript with same author name Clint Eastwood and 
		// after insert manuscript it changes to 3
		assertEquals("manuscripts size: ", manuscriptsList.size(), 2);
		

		Manuscript manuscript = (Manuscript)manuscriptsList.get(1);
		// checking for newly inserted manuscript title and link
		assertEquals("Title: ", manuscript.getTitle(), "New Manuscript Heading");
		assertEquals("Link: ", manuscript.getLink(), "/Papers/Hello.docx");
		assertEquals("Author: ", manuscript.getAuthor(), "Clint Eastwood");
		
	}
	
	// delete manuscript test
	@Test
	public void deleteManuscript() {
		
		ArrayList<Manuscript> mList = new ArrayList<Manuscript>();
		Manuscript new_manuscript = new Manuscript(author.getName(), "Please work", null, null);
		mList.add(new_manuscript);
		
		ArrayList<Manuscript> manuscriptsList1 = fp.getManuscripts(Roles.AUTHOR.toString(), author.getName(), conf.getName());
		// assuming that conference 100 has two manuscript with same author name Clint Eastwood and 
		// after delete the size should be 1
		assertEquals("manuscripts size before delete", manuscriptsList1.size(), 1);
		
		fp.deleteManuscript(Roles.AUTHOR.toString(),conf.getName(), mList);
		
		ArrayList<Manuscript> manuscriptsList = fp.getManuscripts(Roles.AUTHOR.toString(), author.getName(), conf.getName());
		
		assertEquals("manuscripts size after delete", manuscriptsList.size(), 0);
		
        
	}
	
	// save manuscript test
	@Test
	 public void saveManuscript() {
		
		ArrayList<Manuscript> manuscriptsList = fp.getManuscripts(Roles.AUTHOR.toString(), author.getName(), conf.getName());
		Manuscript manuscript = (Manuscript)manuscriptsList.get(0);
		Manuscript aManuscript = new Manuscript(manuscript);
		aManuscript.setTitle("New Title");
		aManuscript.setLink("/papers/newlink.docx");
		// modifying the title and link.Here i am modifying title and link of first manuscript of conference 100.
		// similarly we can change other fields such as approval,rec,sub program name etc by setting above fields in manuscript object
		fp.saveManuscript(manuscript.getTitle(), aManuscript);
		ArrayList<Manuscript> manuscriptsList1 = fp.getManuscripts(Roles.AUTHOR.toString(), author.getName(), conf.getName());
		Manuscript manuscript1 = (Manuscript)manuscriptsList1.get(0);
		// verifying the updated title and link
		assertEquals("new title: ", manuscript1.getTitle(), "New Title");
		assertEquals("new link: ", manuscript1.getLink(), "/papers/newlink.docx");
				
	}
	/*@Test
	public void submitReview() {
		Manuscript manuscript = reviewer.getManuscripts().get(0);
		System.out.println(reviewer.submitReview(manuscript, "/Papers/ChangeFile.docx"));
		Manuscript manuscriptNew = reviewer.getManuscripts().get(0);		
		System.out.println("modified link!!!"+manuscriptNew.getReviews().get(0).getReviewLink());
		assertEquals("Modified link: ", manuscriptNew.getReviews().get(0).getReviewLink(), "/Papers/ChangeFile.docx");
	}*/
	

}
